(function flexible(window, document) {


    var docEl = document.documentElement;

    // 设备像素比




    var dpr = window.devicePixelRatio || 1;

    // 设置body元素字体大小：监听DOM内容是否加载完毕，完毕后给body设置字体大小


    function setBodyFontSize() {

        if (document.body) {

            document.body.style.fontSize = 12 * dpr + "px";

        } else {

            document.addEventListener("DOMContentLoaded", setBodyFontSize);

        }

    }


    setBodyFontSize();

    // 更改根元素字体大小：设置根元素字体大小为屏幕的十分之一




    function setRemUnit() {

        var rem = docEl.clientWidth / 10;


        docEl.style.fontSize = rem + "px";

    }


    setRemUnit();

    // 监听屏幕大小：监听屏幕大小的变化，有变化调用更改根元素字体大小函数




    window.addEventListener("resize", setRemUnit);


    window.addEventListener("pageshow", function (e) {

        if (e.persisted) {

            setRemUnit();

        }

    });


    if (dpr >= 2) {

        var fakeBody = document.createElement("body");

        var testElement = document.createElement("div");


        testElement.style.border = ".5px solid transparent";


        fakeBody.appendChild(testElement);


        docEl.appendChild(fakeBody);

        if (testElement.offsetHeight === 1) {

            docEl.classList.add("hairlines");

        }


        docEl.removeChild(fakeBody);
    }

})(window, document);